<template>
  <div class="main">
    <eagle-input name="PartsCode" label="附件" v-model="form.AttCode">
      <template #input>
        <eagle-image
          @click="chooseFile()"
          width="100"
          height="100"
          :src="urlSrc"
        />
      </template>
    </eagle-input>
    <eagle-input
      name="calendar"
      :value="EquFileTypeName"
      label="附件类型"
      placeholder="请选择"
      readonly
      required
      @click="handleDialog(form.EquFileType)"
      islink
    ></eagle-input>
    <!-- <van-field label="附件类型" name="PartsName"  v-model="info.PartsName" >
    </van-field> -->

    <div class="btn_submit">
      <eagle-button block type="primary" @click="_submit"> 保存 </eagle-button>
    </div>
    <eagle-dialog
      v-model="equpTypeShow"
      v-if="equpTypeShow"
      title="选择附件类型"
	    :titlePosition="'center'"
      :showButtons="false"
      :closeOnClickOverlay="true"
    >
      <eagle-form>
        <div style="margin:0 25px">
          <eagle-radio-group name="radio" label="" v-model="radio" @change="radioChange" :dataSource="selectList" direction="horizontal"></eagle-radio-group>
        </div>
        <div style="margin: 16px"></div>
      </eagle-form>
    </eagle-dialog>

    		<!-- 附件 -->
    <FileListDialog 
      :show.sync="filePopup"
      :selectedValue="form.AttCode"
      @callback="_chooseFileList">
    </FileListDialog>
    
		<!-- <van-popup
			v-model="filePopup"
			closeable
			round
			position="bottom"
			:style="{ height: '80%' }"
		>
			<div class="popup-title"></div>
			<div class="popup-content">
				<FileList @cbFile="_chooseFileList" />
			</div>
		</van-popup> -->
  </div>
</template>

<script>
import FileList from '@/views/components/file/fileList.vue'
import FileListDialog from "@/views/components/file/fileListDialog.vue";
export default {
  components: {FileList,FileListDialog},
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      selectKey: "",
      value: "",
      radio: "1",
      EquFileTypeName: "",
      equpTypeShow: false,
      filePopup:false,
      selectList: [],
      form: {},
      urlSrc: require('../../../assets/Images/AppIcon/image_choose_attach.png')
    };
  },
  created() {
    this.getDict();
  },

  methods: {
    chooseFile() {
      this.filePopup = true
    },

    _chooseFileList(item) {
      this.urlSrc = this.baseUrl + item.AttCover
      this.form.AttCode = item.AttCode
		},
    getDict() {
      let _this = this;
      _this.$axios
      .get("/EquEquipment/GetFileTypes",{params:{}})
      .then((res)=>{
        _this.selectList = res.data;
      })
    },
    handleDialog(val) {
      this.radio = val;
      this.equpTypeShow = true;
    },

    radioChange(names) {
      let select = this.selectList.filter((item) => item.ID == names);
      this.EquFileTypeName = select[0].Name;
      this.form.EquFileType = select[0].ID;
      this.equpTypeShow = false;
    },

    // 保存
    _submit() {
      let _this = this;
      _this.form.ID = _this.$route.query.id
      _this.$axios.post("/EquEquipment/AddEquipmentSafeFileFile",_this.form)
      .then((res)=>{
        if (res.success) {
          _this.$toast.success("新增成功！");
          _this.$router.goRefresh(-1);
        }
      })
      .catch((err)=>{
         console.log("err", err);
      })
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding-top: 10px;
}
.input_text .van-field__control {
  color: #999 !important;
}
</style>
